package cn.edu.swust.adressbook.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import java.util.List;

import cn.edu.swust.adressbook.bean.Group;
import cn.edu.swust.adressbook.view.GroupItemView;


public class GroupItemAdapter extends BaseAdapter {

    private List<Group> mGroups;
    private Context mContext;
    private boolean mIsNeedCheck = false;



    public GroupItemAdapter(Context context) {
        super();
        mContext = context;
    }

    public void setGroups(List<Group> groups) {
        mGroups = groups;
    }

    public void setNeedCheck(boolean needCheck) {
        mIsNeedCheck = needCheck;
    }

    @Override
    public boolean hasStableIds() {
        return true;
    }

    @Override
    public int getCount() {
        return mGroups.size();
    }

    @Override
    public Object getItem(int i) {
        return mGroups.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }


    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        GroupItemView groupItemView;
        if(view == null){
            groupItemView = new GroupItemView(mContext, null);
        } else {
            groupItemView = (GroupItemView) view;
        }
        groupItemView.init(mGroups.get(i));
        groupItemView.setCheckBoxVisibility(mIsNeedCheck);
        return groupItemView;
    }
}
